$(function() {
	$(".edit").on('click', function() {
		var iname = $(this).parents("tr").find(".p-name").text();
		var iaddress = $(this).parents("tr").find(".p-address").text();
		var itel = $(this).parents("tr").find(".p-tel").text();
		// console.log(iname)
		$(".sname").val(iname);
		$(".saddress").val(iaddress);
		$(".sphone").val(itel);
		// console.log($(this).attr("id"))
		$(".save").attr("id", $(this).attr("id"))


	})


	$(".save").on('click', function() {
		let id = $(this).attr("id")
		let name = $(".sname").val();
		let address = $(".saddress").val();
		let phone = $(".sphone").val();
		console.log(phone)
		$.ajax({
			type: "post",
			url: "http://localhost:8080/mall/updateAddress?id=" + id,
			dataType: "json",
			data: {
				"name": name,
				"address": address,
				"tel": phone
			},
			success: function(data) {

				location.reload();
				console.log(data)
			}
		})
	})


	$(".del").on('click', function() {
		let id = $(this).attr("id")
		$.ajax({
			type: "post",
			url: "http://localhost:8080/mall/deleteAddress?id=" + id,
			dataType: "json",
			success: function(data) {
				location.reload();
			}
		})
	})




	$(".edit").on('click',
		function() {
			$('.someinfo').show(500);
		});

	$(".btn-area").on('click',
		function() {
			$('.someinfo').show(500);
			$(".save").on('click', function() {
				let sname = $(".sname").val();
				let sphone = $(".sphone").val();
				let saddress = $(".saddress").val();
				$.ajax({
					type: "post",
					url: "http://localhost:8080/mall/addAddress",
					dataType: "json",
					data: {
						"name": sname,
						"address": saddress,
						"tel": sphone
					},
					success: function(data) {
						location.reload();
					},
				})
			})





		});

	$(".save").on('click',
		function() {
			$('.someinfo').hide(500);
		});

})
